<template>
  <div ref="dropdownRef" class="nav-dropdown">
    <!-- Dropdown button -->
    <a @click="toggleDropdown" class="dropdown-trigger">
      产品服务
      <svg
          :class="isOpen ? 'down' : ''"
          aria-hidden="true"
          class="icon icon-caret"
          role="presentation"
          viewBox="0 0 10 6"
      >
        <path
            clip-rule="evenodd"
            d="M9.354.646a.5.5 0 00-.708 0L5 4.293 1.354.646a.5.5 0 00-.708.708l4 4a.5.5 0 00.708 0l4-4a.5.5 0 000-.708z"
            fill="currentColor"
            fill-rule="evenodd"
        ></path>
      </svg>
    </a>
    <!-- Dropdown menu -->
    <ul v-if="isOpen" class="dropdown-menu">
      <li v-for="(option, index) in options" :key="index">
        <a :href="option.link">{{ option.text }}</a>
      </li>
    </ul>
  </div>
</template>

<script setup>import { ref } from 'vue'

const props = defineProps({
  options: {
    type: Array,
    default: () => [] // 设置默认值为空数组
  }
})

console.log('Props:', props) // 调试信息

const isOpen = ref(false)
const dropdownRef = ref(null)

console.log('Initial options:', props.options) // 调试信息

const toggleDropdown = () => {
  isOpen.value = !isOpen.value
}
</script>

<style scoped>.nav-dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-trigger {
  display: inline-block;
  padding: 10px 15px;
  color: white;
  text-decoration: none;
  cursor: pointer;

}

.dropdown-trigger .icon-caret {
  color: white;
  stroke: white;
  height: 1.3rem;
  width: 1.3rem;
  margin-left: 0.3rem;
  stroke-width: 0.02rem;
  pointer-events: auto;
  transition: transform 0.2s ease-in-out;

  &.down {
    transform: rotate(180deg);
  }
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background-color: white;
  box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
  min-width: 180px;
  z-index: 1;
  margin: 0;
  padding: 0;
  list-style: none;
}

.dropdown-menu li {
  padding: 12px 16px;
}

.dropdown-menu li a {
  display: block;
  color: #333;
  text-decoration: none;
}

.dropdown-menu li a:hover {
  background-color: #f1f1f1;
}
</style>